package com.lnn.springBase.nc;

import java.io.FileInputStream;
import java.io.IOException;

public class BinaryFileSearchFloat {
        public static void main(String[] args) {
            String filePath = "D:\\lnnxy\\Documents\\WeChat Files\\qq735962011\\FileStorage\\File\\2025-04\\RadJw202501200006.00.37.dat";
            float target = 10000f;

            try (FileInputStream fis = new FileInputStream(filePath)) {
                byte[] buffer = new byte[4];
                int index = 0;
                int byteRead;
                while ((byteRead = fis.read()) != -1) {
                    buffer[index] = (byte) byteRead;
                    index++;
                    if (index == 4) {
                        float num = bytesToFloat(buffer);
                        if (Float.compare(num, target) == 0) {
                            System.out.println("找到了 float 类型的 10000！");
                            return;
                        }
                        index = 0;
                    }
                }
                System.out.println("未找到 float 类型的 10000。");
            } catch (IOException e) {
                System.out.println("读取文件时出错: " + e.getMessage());
            }
        }

        public static float bytesToFloat(byte[] bytes) {
            int intBits = ((bytes[0] & 0xFF) << 24) |
                    ((bytes[1] & 0xFF) << 16) |
                    ((bytes[2] & 0xFF) << 8) |
                    (bytes[3] & 0xFF);
            return Float.intBitsToFloat(intBits);
        }
    }
